USE [SI2Final]
GO

/****** Object:  StoredProcedure [dbo].[ConfiguracaoAdd]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ConfiguracaoAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ConfiguracaoAdd]
GO

/****** Object:  StoredProcedure [dbo].[ConfiguracaoDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ConfiguracaoDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ConfiguracaoDelete]
GO

/****** Object:  StoredProcedure [dbo].[ConfiguracaoGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ConfiguracaoGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ConfiguracaoGet]
GO

/****** Object:  StoredProcedure [dbo].[ConfiguracaoGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ConfiguracaoGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ConfiguracaoGetAll]
GO

/****** Object:  StoredProcedure [dbo].[ConfiguracaoUpdate]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ConfiguracaoUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ConfiguracaoUpdate]
GO

/****** Object:  StoredProcedure [dbo].[ConsultaAdd]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ConsultaAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ConsultaAdd]
GO

/****** Object:  StoredProcedure [dbo].[ConsultaDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ConsultaDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ConsultaDelete]
GO

/****** Object:  StoredProcedure [dbo].[ConsultaGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ConsultaGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ConsultaGet]
GO

/****** Object:  StoredProcedure [dbo].[ConsultaGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ConsultaGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ConsultaGetAll]
GO

/****** Object:  StoredProcedure [dbo].[ConsultaUpdate]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ConsultaUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ConsultaUpdate]
GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeAdd]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EspecialidadeAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[EspecialidadeAdd]
GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EspecialidadeDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[EspecialidadeDelete]
GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EspecialidadeGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[EspecialidadeGet]
GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EspecialidadeGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[EspecialidadeGetAll]
GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeMedicoAdd]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EspecialidadeMedicoAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[EspecialidadeMedicoAdd]
GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeMedicoDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EspecialidadeMedicoDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[EspecialidadeMedicoDelete]
GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeMedicoGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EspecialidadeMedicoGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[EspecialidadeMedicoGet]
GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeMedicoGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EspecialidadeMedicoGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[EspecialidadeMedicoGetAll]
GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeUpdate]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EspecialidadeUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[EspecialidadeUpdate]
GO

/****** Object:  StoredProcedure [dbo].[ExameDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ExameDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ExameDelete]
GO

/****** Object:  StoredProcedure [dbo].[ExameGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ExameGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ExameGet]
GO

/****** Object:  StoredProcedure [dbo].[ExameGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ExameGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ExameGetAll]
GO

/****** Object:  StoredProcedure [dbo].[FaturaAdd]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FaturaAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[FaturaAdd]
GO

/****** Object:  StoredProcedure [dbo].[FaturaDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FaturaDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[FaturaDelete]
GO

/****** Object:  StoredProcedure [dbo].[FaturaGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FaturaGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[FaturaGet]
GO

/****** Object:  StoredProcedure [dbo].[FaturaGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FaturaGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[FaturaGetAll]
GO

/****** Object:  StoredProcedure [dbo].[FaturaUpdate]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FaturaUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[FaturaUpdate]
GO

/****** Object:  StoredProcedure [dbo].[ItemFaturaAdd]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ItemFaturaAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ItemFaturaAdd]
GO

/****** Object:  StoredProcedure [dbo].[ItemFaturaDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ItemFaturaDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ItemFaturaDelete]
GO

/****** Object:  StoredProcedure [dbo].[ItemFaturaGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ItemFaturaGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ItemFaturaGet]
GO

/****** Object:  StoredProcedure [dbo].[ItemFaturaGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ItemFaturaGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ItemFaturaGetAll]
GO

/****** Object:  StoredProcedure [dbo].[ItemFaturaUpdate]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ItemFaturaUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ItemFaturaUpdate]
GO

/****** Object:  StoredProcedure [dbo].[MedicamentoAdd]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MedicamentoAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MedicamentoAdd]
GO

/****** Object:  StoredProcedure [dbo].[MedicamentoDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MedicamentoDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MedicamentoDelete]
GO

/****** Object:  StoredProcedure [dbo].[MedicamentoGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MedicamentoGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MedicamentoGet]
GO

/****** Object:  StoredProcedure [dbo].[MedicamentoGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MedicamentoGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MedicamentoGetAll]
GO

/****** Object:  StoredProcedure [dbo].[MedicamentoPacienteAdd]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MedicamentoPacienteAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MedicamentoPacienteAdd]
GO

/****** Object:  StoredProcedure [dbo].[MedicamentoPacienteDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MedicamentoPacienteDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MedicamentoPacienteDelete]
GO

/****** Object:  StoredProcedure [dbo].[MedicamentoPacienteGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MedicamentoPacienteGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MedicamentoPacienteGet]
GO

/****** Object:  StoredProcedure [dbo].[MedicamentoPacienteGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MedicamentoPacienteGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MedicamentoPacienteGetAll]
GO

/****** Object:  StoredProcedure [dbo].[MedicamentoUpdate]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MedicamentoUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MedicamentoUpdate]
GO

/****** Object:  StoredProcedure [dbo].[MedicoAdd]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MedicoAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MedicoAdd]
GO

/****** Object:  StoredProcedure [dbo].[MedicoDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MedicoDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MedicoDelete]
GO

/****** Object:  StoredProcedure [dbo].[MedicoGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MedicoGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MedicoGet]
GO

/****** Object:  StoredProcedure [dbo].[MedicoGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MedicoGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MedicoGetAll]
GO

/****** Object:  StoredProcedure [dbo].[MedicoUpdate]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MedicoUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MedicoUpdate]
GO

/****** Object:  StoredProcedure [dbo].[MoradaAdd]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MoradaAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MoradaAdd]
GO

/****** Object:  StoredProcedure [dbo].[MoradaDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MoradaDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MoradaDelete]
GO

/****** Object:  StoredProcedure [dbo].[MoradaGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MoradaGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MoradaGet]
GO

/****** Object:  StoredProcedure [dbo].[MoradaGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MoradaGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MoradaGetAll]
GO

/****** Object:  StoredProcedure [dbo].[MoradaUpdate]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MoradaUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MoradaUpdate]
GO

/****** Object:  StoredProcedure [dbo].[MotivoConsultaAdd]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MotivoConsultaAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MotivoConsultaAdd]
GO

/****** Object:  StoredProcedure [dbo].[MotivoConsultaDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MotivoConsultaDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MotivoConsultaDelete]
GO

/****** Object:  StoredProcedure [dbo].[MotivoConsultaGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MotivoConsultaGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MotivoConsultaGet]
GO

/****** Object:  StoredProcedure [dbo].[MotivoConsultaGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MotivoConsultaGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MotivoConsultaGetAll]
GO

/****** Object:  StoredProcedure [dbo].[MotivoConsultaUpdate]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MotivoConsultaUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MotivoConsultaUpdate]
GO

/****** Object:  StoredProcedure [dbo].[NacionalidadeAdd]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[NacionalidadeAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[NacionalidadeAdd]
GO

/****** Object:  StoredProcedure [dbo].[NacionalidadeDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[NacionalidadeDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[NacionalidadeDelete]
GO

/****** Object:  StoredProcedure [dbo].[NacionalidadeGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[NacionalidadeGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[NacionalidadeGet]
GO

/****** Object:  StoredProcedure [dbo].[NacionalidadeGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[NacionalidadeGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[NacionalidadeGetAll]
GO

/****** Object:  StoredProcedure [dbo].[NacionalidadeUpdate]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[NacionalidadeUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[NacionalidadeUpdate]
GO

/****** Object:  StoredProcedure [dbo].[PacienteAdd]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PacienteAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PacienteAdd]
GO

/****** Object:  StoredProcedure [dbo].[PacienteDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PacienteDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PacienteDelete]
GO

/****** Object:  StoredProcedure [dbo].[PacienteGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PacienteGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PacienteGet]
GO

/****** Object:  StoredProcedure [dbo].[PacienteGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PacienteGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PacienteGetAll]
GO

/****** Object:  StoredProcedure [dbo].[PacienteLoadAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PacienteLoadAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PacienteLoadAll]
GO

/****** Object:  StoredProcedure [dbo].[PacienteUpdate]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PacienteUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PacienteUpdate]
GO

/****** Object:  StoredProcedure [dbo].[PessoaAdd]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PessoaAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PessoaAdd]
GO

/****** Object:  StoredProcedure [dbo].[PessoaDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PessoaDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PessoaDelete]
GO

/****** Object:  StoredProcedure [dbo].[PessoaGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PessoaGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PessoaGet]
GO

/****** Object:  StoredProcedure [dbo].[PessoaGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PessoaGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PessoaGetAll]
GO

/****** Object:  StoredProcedure [dbo].[PessoaUpdate]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PessoaUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PessoaUpdate]
GO

/****** Object:  StoredProcedure [dbo].[PosologiaAdd]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PosologiaAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PosologiaAdd]
GO

/****** Object:  StoredProcedure [dbo].[PosologiaDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PosologiaDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PosologiaDelete]
GO

/****** Object:  StoredProcedure [dbo].[PosologiaGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PosologiaGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PosologiaGet]
GO

/****** Object:  StoredProcedure [dbo].[PosologiaGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PosologiaGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PosologiaGetAll]
GO

/****** Object:  StoredProcedure [dbo].[PosologiaUpdate]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PosologiaUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PosologiaUpdate]
GO

/****** Object:  StoredProcedure [dbo].[RelatorioDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RelatorioDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[RelatorioDelete]
GO

/****** Object:  StoredProcedure [dbo].[RelatorioExameDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RelatorioExameDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[RelatorioExameDelete]
GO

/****** Object:  StoredProcedure [dbo].[RelatorioExameGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RelatorioExameGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[RelatorioExameGet]
GO

/****** Object:  StoredProcedure [dbo].[RelatorioExameGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RelatorioExameGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[RelatorioExameGetAll]
GO

/****** Object:  StoredProcedure [dbo].[RelatorioGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RelatorioGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[RelatorioGet]
GO

/****** Object:  StoredProcedure [dbo].[RelatorioGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RelatorioGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[RelatorioGetAll]
GO

/****** Object:  StoredProcedure [dbo].[RelatorioMedicoDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RelatorioMedicoDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[RelatorioMedicoDelete]
GO

/****** Object:  StoredProcedure [dbo].[RelatorioMedicoGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RelatorioMedicoGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[RelatorioMedicoGet]
GO

/****** Object:  StoredProcedure [dbo].[RelatorioMedicoGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RelatorioMedicoGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[RelatorioMedicoGetAll]
GO

/****** Object:  StoredProcedure [dbo].[RelatorioMensalFinanceiroAdd]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RelatorioMensalFinanceiroAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[RelatorioMensalFinanceiroAdd]
GO

/****** Object:  StoredProcedure [dbo].[RelatorioMensalFinanceiroDelete]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RelatorioMensalFinanceiroDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[RelatorioMensalFinanceiroDelete]
GO

/****** Object:  StoredProcedure [dbo].[RelatorioMensalFinanceiroGet]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RelatorioMensalFinanceiroGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[RelatorioMensalFinanceiroGet]
GO

/****** Object:  StoredProcedure [dbo].[RelatorioMensalFinanceiroGetAll]    Script Date: 02/24/2012 11:34:44 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RelatorioMensalFinanceiroGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[RelatorioMensalFinanceiroGetAll]
GO

/****** Object:  StoredProcedure [dbo].[RelatorioMensalFinanceiroUpdate]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RelatorioMensalFinanceiroUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[RelatorioMensalFinanceiroUpdate]
GO

/****** Object:  StoredProcedure [dbo].[SistemaSaudeAdd]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SistemaSaudeAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[SistemaSaudeAdd]
GO

/****** Object:  StoredProcedure [dbo].[SistemaSaudeDelete]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SistemaSaudeDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[SistemaSaudeDelete]
GO

/****** Object:  StoredProcedure [dbo].[SistemaSaudeGet]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SistemaSaudeGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[SistemaSaudeGet]
GO

/****** Object:  StoredProcedure [dbo].[SistemaSaudeGetAll]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SistemaSaudeGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[SistemaSaudeGetAll]
GO

/****** Object:  StoredProcedure [dbo].[SistemaSaudeUpdate]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SistemaSaudeUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[SistemaSaudeUpdate]
GO

/****** Object:  StoredProcedure [dbo].[TelefoneAdd]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TelefoneAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[TelefoneAdd]
GO

/****** Object:  StoredProcedure [dbo].[TelefoneDelete]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TelefoneDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[TelefoneDelete]
GO

/****** Object:  StoredProcedure [dbo].[TelefoneGet]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TelefoneGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[TelefoneGet]
GO

/****** Object:  StoredProcedure [dbo].[TelefoneGetAll]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TelefoneGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[TelefoneGetAll]
GO

/****** Object:  StoredProcedure [dbo].[TelefoneUpdate]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TelefoneUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[TelefoneUpdate]
GO

/****** Object:  StoredProcedure [dbo].[TipoContactoAdd]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TipoContactoAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[TipoContactoAdd]
GO

/****** Object:  StoredProcedure [dbo].[TipoContactoDelete]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TipoContactoDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[TipoContactoDelete]
GO

/****** Object:  StoredProcedure [dbo].[TipoContactoGet]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TipoContactoGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[TipoContactoGet]
GO

/****** Object:  StoredProcedure [dbo].[TipoContactoGetAll]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TipoContactoGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[TipoContactoGetAll]
GO

/****** Object:  StoredProcedure [dbo].[TipoContactoUpdate]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TipoContactoUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[TipoContactoUpdate]
GO

/****** Object:  StoredProcedure [dbo].[TipoExameAdd]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TipoExameAdd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[TipoExameAdd]
GO

/****** Object:  StoredProcedure [dbo].[TipoExameDelete]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TipoExameDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[TipoExameDelete]
GO

/****** Object:  StoredProcedure [dbo].[TipoExameGet]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TipoExameGet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[TipoExameGet]
GO

/****** Object:  StoredProcedure [dbo].[TipoExameGetAll]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TipoExameGetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[TipoExameGetAll]
GO

/****** Object:  StoredProcedure [dbo].[TipoExameUpdate]    Script Date: 02/24/2012 11:34:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TipoExameUpdate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[TipoExameUpdate]
GO

USE [SI2Final]
GO

/****** Object:  StoredProcedure [dbo].[ConfiguracaoAdd]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ConfiguracaoAdd]
(
	@Id int = NULL OUTPUT,
	@Chave varchar(50),
	@Valor varchar(50),
	@Observacoes varchar(100)
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[Configuracao]
	(
		[Chave],
		[Valor],
		[Observacoes]
	)
	VALUES
	(
		@Chave,
		@Valor,
		@Observacoes
	)

	SET @Err = @@Error
	SELECT @Id = SCOPE_IDENTITY()

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ConfiguracaoDelete]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ConfiguracaoDelete]
(
	@Id int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[Configuracao]
	WHERE
		[Id] = @Id
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ConfiguracaoGet]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ConfiguracaoGet]
(
	@Id int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Id],
		[Chave],
		[Valor],
		[Observacoes]
	FROM [dbo].[Configuracao]
	WHERE
		([Id] = @Id)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ConfiguracaoGetAll]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ConfiguracaoGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Id],
		[Chave],
		[Valor],
		[Observacoes]
	FROM [dbo].[Configuracao]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ConfiguracaoUpdate]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ConfiguracaoUpdate]
(
	@Id int,
	@Chave varchar(50),
	@Valor varchar(50),
	@Observacoes varchar(100)
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[Configuracao]
	SET
		[Chave] = @Chave,
		[Valor] = @Valor,
		[Observacoes] = @Observacoes
	WHERE
		[Id] = @Id


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ConsultaAdd]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ConsultaAdd]
(
	@IdConsulta int = NULL OUTPUT,
	@IdMotivoConsulta int,
	@Data date,
	@DataRegisto datetime,
	@IdMedico nvarchar(20),
	@IdPaciente int,
	@IdEspecialidade int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[Consulta]
	(
		[IdMotivoConsulta],
		[Data],
		[DataRegisto],
		[IdMedico],
		[IdPaciente],
		[IdEspecialidade]
	)
	VALUES
	(
		@IdMotivoConsulta,
		@Data,
		@DataRegisto,
		@IdMedico,
		@IdPaciente,
		@IdEspecialidade
	)

	SET @Err = @@Error
	SELECT @IdConsulta = SCOPE_IDENTITY()

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ConsultaDelete]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ConsultaDelete]
(
	@IdConsulta int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[Consulta]
	WHERE
		[IdConsulta] = @IdConsulta
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ConsultaGet]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ConsultaGet]
(
	@IdConsulta int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdConsulta],
		[IdMotivoConsulta],
		[Data],
		[DataRegisto],
		[IdMedico],
		[IdPaciente],
		[IdEspecialidade]
	FROM [dbo].[Consulta]
	WHERE
		([IdConsulta] = @IdConsulta)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ConsultaGetAll]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ConsultaGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdConsulta],
		[IdMotivoConsulta],
		[Data],
		[DataRegisto],
		[IdMedico],
		[IdPaciente],
		[IdEspecialidade]
	FROM [dbo].[Consulta]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ConsultaUpdate]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ConsultaUpdate]
(
	@IdConsulta int,
	@IdMotivoConsulta int,
	@Data date,
	@DataRegisto datetime,
	@IdMedico nvarchar(20),
	@IdPaciente int,
	@IdEspecialidade int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[Consulta]
	SET
		[IdMotivoConsulta] = @IdMotivoConsulta,
		[Data] = @Data,
		[DataRegisto] = @DataRegisto,
		[IdMedico] = @IdMedico,
		[IdPaciente] = @IdPaciente,
		[IdEspecialidade] = @IdEspecialidade
	WHERE
		[IdConsulta] = @IdConsulta


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeAdd]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[EspecialidadeAdd]
(
	@IdEspecialidade int = NULL OUTPUT,
	@Nome nvarchar(300),
	@Preco decimal(10,2) = NULL
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[Especialidade]
	(
		[Nome],
		[Preco]
	)
	VALUES
	(
		@Nome,
		@Preco
	)

	SET @Err = @@Error
	SELECT @IdEspecialidade = SCOPE_IDENTITY()

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeDelete]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[EspecialidadeDelete]
(
	@IdEspecialidade int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[Especialidade]
	WHERE
		[IdEspecialidade] = @IdEspecialidade
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeGet]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[EspecialidadeGet]
(
	@IdEspecialidade int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdEspecialidade],
		[Nome],
		[Preco]
	FROM [dbo].[Especialidade]
	WHERE
		([IdEspecialidade] = @IdEspecialidade)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeGetAll]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[EspecialidadeGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdEspecialidade],
		[Nome],
		[Preco]
	FROM [dbo].[Especialidade]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeMedicoAdd]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[EspecialidadeMedicoAdd]
(
	@IdEspecialidade int,
	@IdMedico nvarchar(20)
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[EspecialidadeMedico]
	(
		[IdEspecialidade],
		[IdMedico]
	)
	VALUES
	(
		@IdEspecialidade,
		@IdMedico
	)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeMedicoDelete]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[EspecialidadeMedicoDelete]
(
	@IdEspecialidade int,
	@IdMedico nvarchar(20)
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[EspecialidadeMedico]
	WHERE
		[IdEspecialidade] = @IdEspecialidade AND
		[IdMedico] = @IdMedico
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeMedicoGet]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[EspecialidadeMedicoGet]
(
	@IdEspecialidade int,
	@IdMedico nvarchar(20)
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdEspecialidade],
		[IdMedico]
	FROM [dbo].[EspecialidadeMedico]
	WHERE
		([IdEspecialidade] = @IdEspecialidade) AND
		([IdMedico] = @IdMedico)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeMedicoGetAll]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[EspecialidadeMedicoGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdEspecialidade],
		[IdMedico]
	FROM [dbo].[EspecialidadeMedico]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[EspecialidadeUpdate]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[EspecialidadeUpdate]
(
	@IdEspecialidade int,
	@Nome nvarchar(300),
	@Preco decimal(10,2) = NULL
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[Especialidade]
	SET
		[Nome] = @Nome,
		[Preco] = @Preco
	WHERE
		[IdEspecialidade] = @IdEspecialidade


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ExameDelete]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ExameDelete]
(
	@IdExame int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[Exame]
	WHERE
		[IdExame] = @IdExame
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ExameGet]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ExameGet]
(
	@IdExame int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdExame],
		[Notas],
		[Resultado],
		[IdEquipamento]
	FROM [dbo].[Exame]
	WHERE
		([IdExame] = @IdExame)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ExameGetAll]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ExameGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdExame],
		[Notas],
		[Resultado],
		[IdEquipamento]
	FROM [dbo].[Exame]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[FaturaAdd]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[FaturaAdd]
(
	@IdFatura int,
	@Ano int,
	@Data datetime,
	@Morada nvarchar(2000) = NULL,
	@Nome nvarchar(1250) = NULL,
	@Nif int,
	@DataPagamento smalldatetime
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[Fatura]
	(
		[IdFatura],
		[Ano],
		[Data],
		[Morada],
		[Nome],
		[Nif],
		[DataPagamento]
	)
	VALUES
	(
		@IdFatura,
		@Ano,
		@Data,
		@Morada,
		@Nome,
		@Nif,
		@DataPagamento
	)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[FaturaDelete]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[FaturaDelete]
(
	@IdFatura int,
	@Ano int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[Fatura]
	WHERE
		[IdFatura] = @IdFatura AND
		[Ano] = @Ano
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[FaturaGet]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[FaturaGet]
(
	@IdFatura int,
	@Ano int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdFatura],
		[Ano],
		[Data],
		[Morada],
		[Nome],
		[Nif],
		[DataPagamento]
	FROM [dbo].[Fatura]
	WHERE
		([IdFatura] = @IdFatura) AND
		([Ano] = @Ano)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[FaturaGetAll]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[FaturaGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdFatura],
		[Ano],
		[Data],
		[Morada],
		[Nome],
		[Nif],
		[DataPagamento]
	FROM [dbo].[Fatura]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[FaturaUpdate]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[FaturaUpdate]
(
	@IdFatura int,
	@Ano int,
	@Data datetime,
	@Morada nvarchar(2000) = NULL,
	@Nome nvarchar(1250) = NULL,
	@Nif int,
	@DataPagamento smalldatetime
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[Fatura]
	SET
		[Data] = @Data,
		[Morada] = @Morada,
		[Nome] = @Nome,
		[Nif] = @Nif,
		[DataPagamento] = @DataPagamento
	WHERE
		[IdFatura] = @IdFatura
	AND	[Ano] = @Ano


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ItemFaturaAdd]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ItemFaturaAdd]
(
	@Numero int,
	@Descricao nvarchar(1000) = NULL,
	@Montante decimal(10,2),
	@IdFatura int,
	@Ano int,
	@IdRelatorio int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[ItemFatura]
	(
		[Numero],
		[Descricao],
		[Montante],
		[IdFatura],
		[Ano],
		[IdRelatorio]
	)
	VALUES
	(
		@Numero,
		@Descricao,
		@Montante,
		@IdFatura,
		@Ano,
		@IdRelatorio
	)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ItemFaturaDelete]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ItemFaturaDelete]
(
	@Numero int,
	@IdFatura int,
	@Ano int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[ItemFatura]
	WHERE
		[Numero] = @Numero AND
		[IdFatura] = @IdFatura AND
		[Ano] = @Ano
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ItemFaturaGet]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ItemFaturaGet]
(
	@Numero int,
	@IdFatura int,
	@Ano int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Numero],
		[Descricao],
		[Montante],
		[IdFatura],
		[Ano],
		[IdRelatorio]
	FROM [dbo].[ItemFatura]
	WHERE
		([Numero] = @Numero) AND
		([IdFatura] = @IdFatura) AND
		([Ano] = @Ano)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ItemFaturaGetAll]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ItemFaturaGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Numero],
		[Descricao],
		[Montante],
		[IdFatura],
		[Ano],
		[IdRelatorio]
	FROM [dbo].[ItemFatura]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[ItemFaturaUpdate]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[ItemFaturaUpdate]
(
	@Numero int,
	@Descricao nvarchar(1000) = NULL,
	@Montante decimal(10,2),
	@IdFatura int,
	@Ano int,
	@IdRelatorio int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[ItemFatura]
	SET
		[Descricao] = @Descricao,
		[Montante] = @Montante,
		[IdRelatorio] = @IdRelatorio
	WHERE
		[Numero] = @Numero
	AND	[IdFatura] = @IdFatura
	AND	[Ano] = @Ano


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MedicamentoAdd]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MedicamentoAdd]
(
	@IdMedicamento int = NULL OUTPUT,
	@PrincipioActivo nvarchar(300),
	@NomeComercial nvarchar(300) = NULL,
	@Laboratorio nvarchar(300) = NULL,
	@Dose decimal(4,2) = NULL
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[Medicamento]
	(
		[PrincipioActivo],
		[NomeComercial],
		[Laboratorio],
		[Dose]
	)
	VALUES
	(
		@PrincipioActivo,
		@NomeComercial,
		@Laboratorio,
		@Dose
	)

	SET @Err = @@Error
	SELECT @IdMedicamento = SCOPE_IDENTITY()

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MedicamentoDelete]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MedicamentoDelete]
(
	@IdMedicamento int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[Medicamento]
	WHERE
		[IdMedicamento] = @IdMedicamento
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MedicamentoGet]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MedicamentoGet]
(
	@IdMedicamento int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdMedicamento],
		[PrincipioActivo],
		[NomeComercial],
		[Laboratorio],
		[Dose]
	FROM [dbo].[Medicamento]
	WHERE
		([IdMedicamento] = @IdMedicamento)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MedicamentoGetAll]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MedicamentoGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdMedicamento],
		[PrincipioActivo],
		[NomeComercial],
		[Laboratorio],
		[Dose]
	FROM [dbo].[Medicamento]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MedicamentoPacienteAdd]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MedicamentoPacienteAdd]
(
	@IdMedicamento int,
	@IdPaciente int,
	@IdPosologia int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[MedicamentoPaciente]
	(
		[IdMedicamento],
		[IdPaciente],
		[IdPosologia]
	)
	VALUES
	(
		@IdMedicamento,
		@IdPaciente,
		@IdPosologia
	)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MedicamentoPacienteDelete]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MedicamentoPacienteDelete]
(
	@IdMedicamento int,
	@IdPaciente int,
	@IdPosologia int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[MedicamentoPaciente]
	WHERE
		[IdMedicamento] = @IdMedicamento AND
		[IdPaciente] = @IdPaciente AND
		[IdPosologia] = @IdPosologia
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MedicamentoPacienteGet]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MedicamentoPacienteGet]
(
	@IdMedicamento int,
	@IdPaciente int,
	@IdPosologia int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdMedicamento],
		[IdPaciente],
		[IdPosologia]
	FROM [dbo].[MedicamentoPaciente]
	WHERE
		([IdMedicamento] = @IdMedicamento) AND
		([IdPaciente] = @IdPaciente) AND
		([IdPosologia] = @IdPosologia)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MedicamentoPacienteGetAll]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MedicamentoPacienteGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdMedicamento],
		[IdPaciente],
		[IdPosologia]
	FROM [dbo].[MedicamentoPaciente]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MedicamentoUpdate]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MedicamentoUpdate]
(
	@IdMedicamento int,
	@PrincipioActivo nvarchar(300),
	@NomeComercial nvarchar(300) = NULL,
	@Laboratorio nvarchar(300) = NULL,
	@Dose decimal(4,2) = NULL
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[Medicamento]
	SET
		[PrincipioActivo] = @PrincipioActivo,
		[NomeComercial] = @NomeComercial,
		[Laboratorio] = @Laboratorio,
		[Dose] = @Dose
	WHERE
		[IdMedicamento] = @IdMedicamento


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MedicoAdd]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MedicoAdd]
(
	@LicencaMedica nvarchar(20),
	@DataLicenca date,
	@NumeroPacientesDiario int = NULL,
	@NumeroListadeEspera int = NULL,
	@IdPessoa int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[Medico]
	(
		[LicencaMedica],
		[DataLicenca],
		[NumeroPacientesDiario],
		[NumeroListadeEspera],
		[IdPessoa]
	)
	VALUES
	(
		@LicencaMedica,
		@DataLicenca,
		@NumeroPacientesDiario,
		@NumeroListadeEspera,
		@IdPessoa
	)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MedicoDelete]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MedicoDelete]
(
	@LicencaMedica nvarchar(20)
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[Medico]
	WHERE
		[LicencaMedica] = @LicencaMedica
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MedicoGet]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MedicoGet]
(
	@LicencaMedica nvarchar(20)
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[LicencaMedica],
		[DataLicenca],
		[NumeroPacientesDiario],
		[NumeroListadeEspera],
		[IdPessoa]
	FROM [dbo].[Medico]
	WHERE
		([LicencaMedica] = @LicencaMedica)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MedicoGetAll]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MedicoGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[LicencaMedica],
		[DataLicenca],
		[NumeroPacientesDiario],
		[NumeroListadeEspera],
		[IdPessoa]
	FROM [dbo].[Medico]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MedicoUpdate]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MedicoUpdate]
(
	@LicencaMedica nvarchar(20),
	@DataLicenca date,
	@NumeroPacientesDiario int = NULL,
	@NumeroListadeEspera int = NULL,
	@IdPessoa int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[Medico]
	SET
		[DataLicenca] = @DataLicenca,
		[NumeroPacientesDiario] = @NumeroPacientesDiario,
		[NumeroListadeEspera] = @NumeroListadeEspera,
		[IdPessoa] = @IdPessoa
	WHERE
		[LicencaMedica] = @LicencaMedica


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MoradaAdd]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MoradaAdd]
(
	@Ordem smallint,
	@Rua nvarchar(1000),
	@Numero nvarchar(9) = NULL,
	@CodigoPostar nvarchar(8) = NULL,
	@Cidade nvarchar(300) = NULL,
	@Pais nvarchar(300) = NULL,
	@IdPessoa int,
	@IdTipoContacto int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[Morada]
	(
		[Ordem],
		[Rua],
		[Numero],
		[CodigoPostar],
		[Cidade],
		[Pais],
		[IdPessoa],
		[IdTipoContacto]
	)
	VALUES
	(
		@Ordem,
		@Rua,
		@Numero,
		@CodigoPostar,
		@Cidade,
		@Pais,
		@IdPessoa,
		@IdTipoContacto
	)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MoradaDelete]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MoradaDelete]
(
	@Ordem smallint
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[Morada]
	WHERE
		[Ordem] = @Ordem
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MoradaGet]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MoradaGet]
(
	@Ordem smallint
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Ordem],
		[Rua],
		[Numero],
		[CodigoPostar],
		[Cidade],
		[Pais],
		[IdPessoa],
		[IdTipoContacto]
	FROM [dbo].[Morada]
	WHERE
		([Ordem] = @Ordem)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MoradaGetAll]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MoradaGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Ordem],
		[Rua],
		[Numero],
		[CodigoPostar],
		[Cidade],
		[Pais],
		[IdPessoa],
		[IdTipoContacto]
	FROM [dbo].[Morada]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MoradaUpdate]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MoradaUpdate]
(
	@Ordem smallint,
	@Rua nvarchar(1000),
	@Numero nvarchar(9) = NULL,
	@CodigoPostar nvarchar(8) = NULL,
	@Cidade nvarchar(300) = NULL,
	@Pais nvarchar(300) = NULL,
	@IdPessoa int,
	@IdTipoContacto int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[Morada]
	SET
		[Rua] = @Rua,
		[Numero] = @Numero,
		[CodigoPostar] = @CodigoPostar,
		[Cidade] = @Cidade,
		[Pais] = @Pais,
		[IdPessoa] = @IdPessoa,
		[IdTipoContacto] = @IdTipoContacto
	WHERE
		[Ordem] = @Ordem


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MotivoConsultaAdd]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MotivoConsultaAdd]
(
	@IdMotivoConsulta int = NULL OUTPUT,
	@Descricao nvarchar(50)
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[MotivoConsulta]
	(
		[Descricao]
	)
	VALUES
	(
		@Descricao
	)

	SET @Err = @@Error
	SELECT @IdMotivoConsulta = SCOPE_IDENTITY()

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MotivoConsultaDelete]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MotivoConsultaDelete]
(
	@IdMotivoConsulta int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[MotivoConsulta]
	WHERE
		[IdMotivoConsulta] = @IdMotivoConsulta
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MotivoConsultaGet]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MotivoConsultaGet]
(
	@IdMotivoConsulta int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdMotivoConsulta],
		[Descricao]
	FROM [dbo].[MotivoConsulta]
	WHERE
		([IdMotivoConsulta] = @IdMotivoConsulta)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MotivoConsultaGetAll]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MotivoConsultaGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdMotivoConsulta],
		[Descricao]
	FROM [dbo].[MotivoConsulta]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[MotivoConsultaUpdate]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MotivoConsultaUpdate]
(
	@IdMotivoConsulta int,
	@Descricao nvarchar(50)
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[MotivoConsulta]
	SET
		[Descricao] = @Descricao
	WHERE
		[IdMotivoConsulta] = @IdMotivoConsulta


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[NacionalidadeAdd]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[NacionalidadeAdd]
(
	@Id int = NULL OUTPUT,
	@Descricao varchar(50)
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[Nacionalidade]
	(
		[Descricao]
	)
	VALUES
	(
		@Descricao
	)

	SET @Err = @@Error
	SELECT @Id = SCOPE_IDENTITY()

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[NacionalidadeDelete]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[NacionalidadeDelete]
(
	@Id int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[Nacionalidade]
	WHERE
		[Id] = @Id
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[NacionalidadeGet]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[NacionalidadeGet]
(
	@Id int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Id],
		[Descricao]
	FROM [dbo].[Nacionalidade]
	WHERE
		([Id] = @Id)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[NacionalidadeGetAll]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[NacionalidadeGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Id],
		[Descricao]
	FROM [dbo].[Nacionalidade]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[NacionalidadeUpdate]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[NacionalidadeUpdate]
(
	@Id int,
	@Descricao varchar(50)
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[Nacionalidade]
	SET
		[Descricao] = @Descricao
	WHERE
		[Id] = @Id


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[PacienteAdd]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PacienteAdd]
(
	@NumeroBenefeciario int,
	@IdSistemaSaude int = NULL,
	@IdPessoa int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[Paciente]
	(
		[NumeroBenefeciario],
		[IdSistemaSaude],
		[IdPessoa]
	)
	VALUES
	(
		@NumeroBenefeciario,
		@IdSistemaSaude,
		@IdPessoa
	)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[PacienteDelete]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PacienteDelete]
(
	@NumeroBenefeciario int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[Paciente]
	WHERE
		[NumeroBenefeciario] = @NumeroBenefeciario
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[PacienteGet]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PacienteGet]
(
	@NumeroBenefeciario int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[NumeroBenefeciario],
		[IdSistemaSaude],
		[IdPessoa]
	FROM [dbo].[Paciente]
	WHERE
		([NumeroBenefeciario] = @NumeroBenefeciario)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[PacienteGetAll]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PacienteGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT     Paciente.NumeroBenefeciario, Paciente.IdSistemaSaude, Paciente.IdPessoa, Pessoa.Nif, Pessoa.NumeroSS, Pessoa.Nome, Pessoa.UltimoNome, 
                      Pessoa.DataNascimento, Pessoa.IdNacionalidade, Pessoa.EMail, Nacionalidade.Descricao, SistemaSaude.Descricao AS Expr1
FROM         Nacionalidade INNER JOIN
                      Pessoa ON Nacionalidade.Id = Pessoa.IdNacionalidade INNER JOIN
                      Paciente ON Pessoa.NumeroSS = Paciente.IdPessoa INNER JOIN
                      SistemaSaude ON Paciente.IdSistemaSaude = SistemaSaude.Id

	SET @Err = @@Error

	RETURN @Err
END


GO

/****** Object:  StoredProcedure [dbo].[PacienteLoadAll]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PacienteLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT     Paciente.NumeroBenefeciario, Paciente.IdSistemaSaude, Paciente.IdPessoa, Pessoa.Nif, Pessoa.NumeroSS, Pessoa.Nome, Pessoa.UltimoNome, 
                      Pessoa.DataNascimento, Pessoa.IdNacionalidade, Pessoa.EMail, Nacionalidade.Descricao as Nacionalidade, SistemaSaude.Descricao AS SistemaSaude
FROM         Nacionalidade INNER JOIN
                      Pessoa ON Nacionalidade.Id = Pessoa.IdNacionalidade INNER JOIN
                      Paciente ON Pessoa.NumeroSS = Paciente.IdPessoa INNER JOIN
                      SistemaSaude ON Paciente.IdSistemaSaude = SistemaSaude.Id

	SET @Err = @@Error

	RETURN @Err
END


GO

/****** Object:  StoredProcedure [dbo].[PacienteUpdate]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PacienteUpdate]
(
	@NumeroBenefeciario int,
	@IdSistemaSaude int = NULL,
	@IdPessoa int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[Paciente]
	SET
		[IdSistemaSaude] = @IdSistemaSaude,
		[IdPessoa] = @IdPessoa
	WHERE
		[NumeroBenefeciario] = @NumeroBenefeciario


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[PessoaAdd]    Script Date: 02/24/2012 11:34:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PessoaAdd]
(
	@Nif int,
	@NumeroSS int,
	@Nome nvarchar(1000),
	@UltimoNome nvarchar(250),
	@DataNascimento date,
	@IdNacionalidade int,
	@EMail nvarchar(1000) = NULL
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[Pessoa]
	(
		[Nif],
		[NumeroSS],
		[Nome],
		[UltimoNome],
		[DataNascimento],
		[IdNacionalidade],
		[EMail]
	)
	VALUES
	(
		@Nif,
		@NumeroSS,
		@Nome,
		@UltimoNome,
		@DataNascimento,
		@IdNacionalidade,
		@EMail
	)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[PessoaDelete]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PessoaDelete]
(
	@NumeroSS int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[Pessoa]
	WHERE
		[NumeroSS] = @NumeroSS
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[PessoaGet]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PessoaGet]
(
	@NumeroSS int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Nif],
		[NumeroSS],
		[Nome],
		[UltimoNome],
		[DataNascimento],
		[IdNacionalidade],
		[EMail]
	FROM [dbo].[Pessoa]
	WHERE
		([NumeroSS] = @NumeroSS)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[PessoaGetAll]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PessoaGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Nif],
		[NumeroSS],
		[Nome],
		[UltimoNome],
		[DataNascimento],
		[IdNacionalidade],
		[EMail]
	FROM [dbo].[Pessoa]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[PessoaUpdate]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PessoaUpdate]
(
	@Nif int,
	@NumeroSS int,
	@Nome nvarchar(1000),
	@UltimoNome nvarchar(250),
	@DataNascimento date,
	@IdNacionalidade int,
	@EMail nvarchar(1000) = NULL
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[Pessoa]
	SET
		[Nif] = @Nif,
		[Nome] = @Nome,
		[UltimoNome] = @UltimoNome,
		[DataNascimento] = @DataNascimento,
		[IdNacionalidade] = @IdNacionalidade,
		[EMail] = @EMail
	WHERE
		[NumeroSS] = @NumeroSS


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[PosologiaAdd]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PosologiaAdd]
(
	@IdPosologia int = NULL OUTPUT,
	@Descricao nvarchar(50)
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[Posologia]
	(
		[Descricao]
	)
	VALUES
	(
		@Descricao
	)

	SET @Err = @@Error
	SELECT @IdPosologia = SCOPE_IDENTITY()

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[PosologiaDelete]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PosologiaDelete]
(
	@IdPosologia int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[Posologia]
	WHERE
		[IdPosologia] = @IdPosologia
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[PosologiaGet]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PosologiaGet]
(
	@IdPosologia int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdPosologia],
		[Descricao]
	FROM [dbo].[Posologia]
	WHERE
		([IdPosologia] = @IdPosologia)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[PosologiaGetAll]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PosologiaGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdPosologia],
		[Descricao]
	FROM [dbo].[Posologia]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[PosologiaUpdate]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PosologiaUpdate]
(
	@IdPosologia int,
	@Descricao nvarchar(50)
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[Posologia]
	SET
		[Descricao] = @Descricao
	WHERE
		[IdPosologia] = @IdPosologia


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[RelatorioDelete]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[RelatorioDelete]
(
	@IdRelatorio int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[Relatorio]
	WHERE
		[IdRelatorio] = @IdRelatorio
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[RelatorioExameDelete]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[RelatorioExameDelete]
(
	@IdRelatorio int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[RelatorioExame]
	WHERE
		[IdRelatorio] = @IdRelatorio
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[RelatorioExameGet]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[RelatorioExameGet]
(
	@IdRelatorio int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdRelatorio],
		[IdEquipamento],
		[Notas],
		[Tipo]
	FROM [dbo].[RelatorioExame]
	WHERE
		([IdRelatorio] = @IdRelatorio)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[RelatorioExameGetAll]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[RelatorioExameGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdRelatorio],
		[IdEquipamento],
		[Notas],
		[Tipo]
	FROM [dbo].[RelatorioExame]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[RelatorioGet]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[RelatorioGet]
(
	@IdRelatorio int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdRelatorio],
		[Data],
		[Descricao],
		[IdConsulta]
	FROM [dbo].[Relatorio]
	WHERE
		([IdRelatorio] = @IdRelatorio)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[RelatorioGetAll]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[RelatorioGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdRelatorio],
		[Data],
		[Descricao],
		[IdConsulta]
	FROM [dbo].[Relatorio]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[RelatorioMedicoDelete]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[RelatorioMedicoDelete]
(
	@IdRelatorio int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[RelatorioMedico]
	WHERE
		[IdRelatorio] = @IdRelatorio
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[RelatorioMedicoGet]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[RelatorioMedicoGet]
(
	@IdRelatorio int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdRelatorio],
		[EstadoClinico],
		[Prescricoes]
	FROM [dbo].[RelatorioMedico]
	WHERE
		([IdRelatorio] = @IdRelatorio)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[RelatorioMedicoGetAll]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[RelatorioMedicoGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdRelatorio],
		[EstadoClinico],
		[Prescricoes]
	FROM [dbo].[RelatorioMedico]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[RelatorioMensalFinanceiroAdd]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[RelatorioMensalFinanceiroAdd]
(
	@Ano int,
	@Mes int,
	@Relatorio xml = NULL
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[RelatorioMensalFinanceiro]
	(
		[Ano],
		[Mes],
		[Relatorio]
	)
	VALUES
	(
		@Ano,
		@Mes,
		@Relatorio
	)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[RelatorioMensalFinanceiroDelete]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[RelatorioMensalFinanceiroDelete]
(
	@Ano int,
	@Mes int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[RelatorioMensalFinanceiro]
	WHERE
		[Ano] = @Ano AND
		[Mes] = @Mes
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[RelatorioMensalFinanceiroGet]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[RelatorioMensalFinanceiroGet]
(
	@Ano int,
	@Mes int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Ano],
		[Mes],
		[Relatorio]
	FROM [dbo].[RelatorioMensalFinanceiro]
	WHERE
		([Ano] = @Ano) AND
		([Mes] = @Mes)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[RelatorioMensalFinanceiroGetAll]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[RelatorioMensalFinanceiroGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Ano],
		[Mes],
		[Relatorio]
	FROM [dbo].[RelatorioMensalFinanceiro]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[RelatorioMensalFinanceiroUpdate]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[RelatorioMensalFinanceiroUpdate]
(
	@Ano int,
	@Mes int,
	@Relatorio xml = NULL
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[RelatorioMensalFinanceiro]
	SET
		[Relatorio] = @Relatorio
	WHERE
		[Ano] = @Ano
	AND	[Mes] = @Mes


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[SistemaSaudeAdd]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[SistemaSaudeAdd]
(
	@Id int = NULL OUTPUT,
	@Descricao varchar(50)
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[SistemaSaude]
	(
		[Descricao]
	)
	VALUES
	(
		@Descricao
	)

	SET @Err = @@Error
	SELECT @Id = SCOPE_IDENTITY()

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[SistemaSaudeDelete]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[SistemaSaudeDelete]
(
	@Id int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[SistemaSaude]
	WHERE
		[Id] = @Id
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[SistemaSaudeGet]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[SistemaSaudeGet]
(
	@Id int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Id],
		[Descricao]
	FROM [dbo].[SistemaSaude]
	WHERE
		([Id] = @Id)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[SistemaSaudeGetAll]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[SistemaSaudeGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Id],
		[Descricao]
	FROM [dbo].[SistemaSaude]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[SistemaSaudeUpdate]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[SistemaSaudeUpdate]
(
	@Id int,
	@Descricao varchar(50)
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[SistemaSaude]
	SET
		[Descricao] = @Descricao
	WHERE
		[Id] = @Id


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[TelefoneAdd]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[TelefoneAdd]
(
	@Ordem int,
	@Numero nvarchar(15) = NULL,
	@IdPessoa int,
	@IdTipoContacto int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[Telefone]
	(
		[Ordem],
		[Numero],
		[IdPessoa],
		[IdTipoContacto]
	)
	VALUES
	(
		@Ordem,
		@Numero,
		@IdPessoa,
		@IdTipoContacto
	)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[TelefoneDelete]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[TelefoneDelete]
(
	@Ordem int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[Telefone]
	WHERE
		[Ordem] = @Ordem
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[TelefoneGet]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[TelefoneGet]
(
	@Ordem int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Ordem],
		[Numero],
		[IdPessoa],
		[IdTipoContacto]
	FROM [dbo].[Telefone]
	WHERE
		([Ordem] = @Ordem)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[TelefoneGetAll]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[TelefoneGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Ordem],
		[Numero],
		[IdPessoa],
		[IdTipoContacto]
	FROM [dbo].[Telefone]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[TelefoneUpdate]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[TelefoneUpdate]
(
	@Ordem int,
	@Numero nvarchar(15) = NULL,
	@IdPessoa int,
	@IdTipoContacto int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[Telefone]
	SET
		[Numero] = @Numero,
		[IdPessoa] = @IdPessoa,
		[IdTipoContacto] = @IdTipoContacto
	WHERE
		[Ordem] = @Ordem


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[TipoContactoAdd]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[TipoContactoAdd]
(
	@Tipo int,
	@Descricao nvarchar(250) = NULL
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[TipoContacto]
	(
		[Tipo],
		[Descricao]
	)
	VALUES
	(
		@Tipo,
		@Descricao
	)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[TipoContactoDelete]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[TipoContactoDelete]
(
	@Tipo int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[TipoContacto]
	WHERE
		[Tipo] = @Tipo
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[TipoContactoGet]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[TipoContactoGet]
(
	@Tipo int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Tipo],
		[Descricao]
	FROM [dbo].[TipoContacto]
	WHERE
		([Tipo] = @Tipo)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[TipoContactoGetAll]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[TipoContactoGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Tipo],
		[Descricao]
	FROM [dbo].[TipoContacto]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[TipoContactoUpdate]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[TipoContactoUpdate]
(
	@Tipo int,
	@Descricao nvarchar(250) = NULL
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[TipoContacto]
	SET
		[Descricao] = @Descricao
	WHERE
		[Tipo] = @Tipo


	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[TipoExameAdd]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[TipoExameAdd]
(
	@IdTipoExame int,
	@Nome nvarchar(500) = NULL,
	@Preco decimal(10,2) = NULL
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	INSERT
	INTO [dbo].[TipoExame]
	(
		[IdTipoExame],
		[Nome],
		[Preco]
	)
	VALUES
	(
		@IdTipoExame,
		@Nome,
		@Preco
	)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[TipoExameDelete]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[TipoExameDelete]
(
	@IdTipoExame int
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	DELETE
	FROM [dbo].[TipoExame]
	WHERE
		[IdTipoExame] = @IdTipoExame
	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[TipoExameGet]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[TipoExameGet]
(
	@IdTipoExame int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdTipoExame],
		[Nome],
		[Preco]
	FROM [dbo].[TipoExame]
	WHERE
		([IdTipoExame] = @IdTipoExame)

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[TipoExameGetAll]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[TipoExameGetAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[IdTipoExame],
		[Nome],
		[Preco]
	FROM [dbo].[TipoExame]

	SET @Err = @@Error

	RETURN @Err
END

GO

/****** Object:  StoredProcedure [dbo].[TipoExameUpdate]    Script Date: 02/24/2012 11:34:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[TipoExameUpdate]
(
	@IdTipoExame int,
	@Nome nvarchar(500) = NULL,
	@Preco decimal(10,2) = NULL
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	UPDATE [dbo].[TipoExame]
	SET
		[Nome] = @Nome,
		[Preco] = @Preco
	WHERE
		[IdTipoExame] = @IdTipoExame


	SET @Err = @@Error

	RETURN @Err
END

GO


